<?php

namespace app\admin\service;

use app\admin\dao\ConsultingDao;
use app\admin\model\UM as UM;
use app\common\model\Consulting;
use ShidianUtil\Exception\DataNotExistException;

/**
 * Class ConsultingHiddenService
 * @package app\admin\service
 */
class ConsultingHiddenService
{
    // dao
    private ConsultingDao $consultingDao;

    public function __construct(ConsultingDao $consultingDao)
    {
        $this->consultingDao = $consultingDao;
    }

    /**
     * 更新
     * @param UM $user
     * @param int $id
     * @param array $params
     * @return Consulting
     */
    public function modify(UM $user, int $id, array $params): Consulting
    {
        //这里如果要修改查询，建议把查询就放到这里
        $record = Consulting::field(true)->where('id', $id)->find();

        if (is_null($record)) {
            throw new DataNotExistException('该咨询不存在或已被删除');
        }

        $allowField = ['isHidden'];
        $this->consultingDao->updateActive($record, $params, $allowField);

        return $record;
    }
}
